package com.foxzzz.two.pointers;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

public class Solution345 {
    private static Set<Character> set = new HashSet<>();

    static {
        Collections.addAll(set, 'a', 'e', 'i', 'o', 'u');
    }

    public String reverseVowels(String s) {
        if (s.length() == 0) {
            return s;
        }
        int low = 0;
        int high = s.length() - 1;
        char[] chars = s.toCharArray();
        while (low < high) {
            //chars[low]|32 大写变小写
            while (low<high&&!set.contains(Character.valueOf((char) (chars[low] | 32)))) {
                low++;
            }
            while (low<high&&!set.contains(Character.valueOf((char) (chars[high] | 32)))) {
                high--;
            }
            if (low < high) {
                char temp = chars[low];
                chars[low] = chars[high];
                chars[high] = temp;
            }
            low++;
            high--;
        }
        return new String(chars);
    }

    public static void main(String[] args) {
        System.out.println(new Solution345().reverseVowels(".,"));
        System.out.println(new Solution345().reverseVowels("leetcode"));


    }
}
